// src/components/auth/role-gate.tsx
'use client';
import React from 'react';
import {UserRole} from "@/lib/types";
import {useCurrentRole} from "@/hooks/use-current-role";
import FormError from "@/components/form-error";

interface Props {
    children: React.ReactNode;
    allowedRole: UserRole
}

const RoleGate = ({children, allowedRole}: Props) => {
    const role = useCurrentRole()
    if (role !== allowedRole) {
        return (
            <FormError message={`You do not have permission to view this content!`}/>
        )
    }

    return (
        <>
            {children}
        </>
    );
};

export default RoleGate;